public class javaTest {
    public int findPeakElement (int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        while(left < right){
            int mid = (left + right) / 2;
            //右边是往下，不一定有坡峰
            if(nums[mid] > nums[mid + 1])
                right = mid;
            //，一定能找到波峰
            else
            left = mid + 1;
        }
        //返回其中一个波峰
        return right;
    }

    // 让AI生成的测试示例1
    public void testExample1() {
        int[] nums = {2, 4, 1, 2, 7, 8, 1};
        int result = findPeakElement(nums);
        System.out.println("示例1代码返回结果：" + result);
        System.out.println("示例1预期结果：1或5");
        System.out.println("是否正确：" + (result == 1 || result == 5 ? "是" : "否"));

    }

    // 让AI生成的测试示例2
    public void testExample2() {
        int[] nums = {1, 2, 3, 1};
        int result = findPeakElement(nums);
        System.out.println("示例2代码返回结果：" + result);
        System.out.println("示例2预期结果：2");
        System.out.println("是否正确：" + (result == 2 ? "是" : "否"));
    }

    public static void main(String[] args) {
        javaTest test = new javaTest();
        test.testExample1();
        System.out.println("------------------------");
        test.testExample2();
    }

}